package com.my.hp_hr.contorller.liuhao_controller;

import com.my.hp_hr.entity.liuhao_entity.Employee;
import com.my.hp_hr.service.liuhao_service.EmployeeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/update.do")
public class EmployeeUpdateServlet extends HttpServlet {
    public EmployeeService employeeService=new EmployeeService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            int employee_number = Integer.valueOf(req.getParameter("employee_number"));
            String name = req.getParameter("name");
            String password = req.getParameter("password");
            String gender = req.getParameter("gender");
            String birthday_str = req.getParameter("birthday");
            String telephone = req.getParameter("telephone");
            String email = req.getParameter("email");
            String address = req.getParameter("address");
            String education = req.getParameter("education");
            String notes = req.getParameter("notes");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date birthday = simpleDateFormat.parse(birthday_str);
            Employee employee_isLogin = (Employee) req.getSession().getAttribute("employee_isLogin");
            Employee employee = new Employee(employee_isLogin.getId(), employee_number, name, gender, birthday, telephone, email, address, null, education, 0, 0, new Date(), password, notes, null, null);
            employeeService.updateEmployeeInfo(employee);
            req.getRequestDispatcher("toUpdate.do").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
